package jm.algorithm.sort;

import jm.algorithm.tools.Asserts;
import jm.algorithm.tools.Integers;
import jm.algorithm.tools.Times;

import java.util.Arrays;

/**
 * @Description 排序测试
 * @date 2022/5/2 9:20
 */
@SuppressWarnings({"rawtypes","unchecked"})
public class SortMain {
    public static void main(String[] args) {
        Integer[] arr = Integers.random(20000, 1, 2000);
        testSort(new Sort[]{
                new HeapSort(),
                new SelectionSort(),
                new BubbleSort(),
                new InsertionSort(),
                new MergeSort(),
                new QuickSort(),
                new ShellSort(),
                new CountingSortPro(),
                new RadixSort(),
        },arr);
    }

    static void testSort(Sort[] sorts,Integer[] arr){
        for (Sort sort : sorts) {
            Integer[] newArr = Integers.copy(arr);
            sort.sort(newArr);
            Asserts.test(Integers.isAscOrder(newArr), sort.getClass().getSimpleName());
        }
        Arrays.sort(sorts);

        for (Sort sort : sorts) {
            System.out.println(sort);
        }
    }
}
